<!DOCTYPE html>
<html>
<head>
  <title>在线编辑工具</title>
  <style>
    #editor {
      width: 100%;
      height: 200px;
    }
  </style>
</head>
<body>
  <textarea id="editor"></textarea>
  <button onclick="runCode()">运行代码</button>
  <hr>
  <div id="output"></div>

  <script>
    function runCode() {
      var code = document.getElementById('editor').value;
      var output = document.getElementById('output');
      output.innerHTML = "";
      var iframe = document.createElement('iframe');
      iframe.style.width = "100%";
      iframe.style.height = "400px";
      output.appendChild(iframe);

      var doc = iframe.contentDocument || iframe.contentWindow.document;
      doc.open();
      doc.write(code);
      doc.close();
    }
  </script>
</body>
</html>
